package com.niodata.dp.core.hdfs.legacy;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.DirectoryStream.Filter;
import java.util.List;

/**
 * interface for file system.
 *
 * @author huqiao
 */
public interface DpFileSystem {

  /**
   * list files(including files and directory) in path (no recursion).
   */
  List<DpFileStatus> listFiles(String path, Integer limit, Integer page)
        throws IOException, DpFsException;

  /**
   * list files(including files and directory) that matches filter in dir (no recursion).
   *
   * @param path dir
   * @param filter filter
   * @param limit limit
   * @param page 0 means the first page
   * @return list of filestatus
   * @throws IOException error
   */
  List<DpFileStatus> listFiles(String path, Filter<DpFileStatus> filter,
        Integer limit, Integer page) throws IOException;

  void mkdir(String path) throws IOException;

  void mkdirs(String path) throws IOException;

  void delete(String path, boolean recursive) throws IOException;

  void copyFromLocal(String src, String target) throws IOException;

  void copyToLocal(String src, String target) throws IOException;

  long write(String path, InputStream is, boolean overwrite) throws IOException;

  InputStream open(String path) throws IOException;

  OutputStream create(String path, boolean overwrite) throws IOException;

  /**
   * True iff the named path is a directory.
   *
   * @param path path
   * @return true if the named path is a directory.(return false if the directory is not exist)
   * @throws DpFsException error
   */
  boolean isDirectory(String path) throws IOException;

  /**
   * True iff the named path is a regular file.
   *
   * @param path path
   * @return true iff the named path is a regular file.(when the file is not exist,it returns false)
   * @throws DpFsException error
   */
  boolean isFile(String path) throws IOException;

  long getCapacity() throws IOException;

  long getUsed() throws IOException;

  boolean exist(String path) throws IOException;

  void close() throws IOException;

  long getFileSize(String path) throws IOException;

}